CMAKE_MINIMUM_REQUIRED(VERSION 3.27.8)
PROJECT(tbs_cpp VERSION 0.1.0 LANGUAGES C CXX)

SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_STANDARD 20)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/runtime)
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/runtime)
SET(SOURCE_PATH ${CMAKE_SOURCE_DIR}/impl)
SET(PROJECT_HEAD ${CMAKE_SOURCE_DIR}/include)
SET(INLS_SOURCE ${CMAKE_SOURCE_DIR}/include/inls)

OPTION(CMAKE_LIB_BUILD_STATIC "库文件是否为静态，否为动态库" ON)


IF (WIN32)
    MESSAGE(STATUS "WINDOWS PLATFORM")
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
    SET(HEADER_PATH "C:\\msys64\\mingw64\\include")
    SET(LIB_PATH ${CMAKE_SOURCE_DIR}/lib "C:\\msys64\\mingw64\\lib")
ELSEIF (APPLE)
    MESSAGE(STATUS "APPLE PLATFORM")
    SET(HEADER_PATH /opt/homebrew/include /opt/homebrew/opt/llvm@17/include)
    SET(LIB_PATH ${CMAKE_SOURCE_DIR}/lib /opt/homebrew/lib /opt/homebrew/opt/llvm@17/lib/c++)
    SET(CMAKE_OSX_SYSROOT /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk)
ENDIF ()

ADD_SUBDIRECTORY(tbs_cpp_tester)
INCLUDE_DIRECTORIES(BEFORE ${HEADER_PATH} ${PROJECT_HEAD} ${INLS_SOURCE})
LINK_DIRECTORIES(BEFORE ${LIB_PATH})
MESSAGE(STATUS "searching for sources...")
FILE(GLOB_RECURSE SOURCES ${SOURCE_PATH}/**.cpp ${SOURCE_PATH}/**.c)
FOREACH (ITEM IN LISTS SOURCES)
    MESSAGE(STATUS "Source file: ${ITEM}")
ENDFOREACH ()

MESSAGE(STATUS "searching for headers...")
FILE(GLOB_RECURSE HEADERS ${PROJECT_HEAD}/**.h ${PROJECT_HEAD}/**.hpp)
FOREACH (ITEM IN LISTS HEADERS)
    MESSAGE(STATUS "header file: ${ITEM}")
ENDFOREACH ()

MESSAGE(STATUS "searching for headers inls...")
FILE(GLOB_RECURSE HEADER_INLS ${INLS_SOURCE}/**.cuh)
FOREACH (ITEM IN LISTS HEADER_INLS)
    MESSAGE(STATUS "head inls file: ${ITEM}")
ENDFOREACH ()


IF (CMAKE_LIB_BUILD_STATIC)
    MESSAGE(STATUS "static lib build")
    ADD_LIBRARY(tbs_cpp STATIC ${HEADERS} ${HEADER_INLS} ${SOURCES})
ELSE ()
    MESSAGE(STATUS "dynamic lib build")
    ADD_LIBRARY(tbs_cpp SHARED ${HEADERS} ${HEADER_INLS} ${SOURCES})
ENDIF ()